package com.woniuxy.educationplatform.service.impl;

import com.woniuxy.educationplatform.bean.GoodsBean;
import com.woniuxy.educationplatform.mapper.GoodsMapper;
import com.woniuxy.educationplatform.service.IGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class GoodsServiceImpl implements IGoodsService {

    @Resource
    private GoodsMapper goodsMapperImpl;

    /**
     * 通过Id查询商品
     *
     * @param id
     * @return
     */
    @Override
    public GoodsBean findById(Integer id) {
        return goodsMapperImpl.findById(id);
    }

    /**
     * 分页查询所有的商品
     *
     * @return
     */
   /* @Override
    public PageInfo<GoodsBean> findAll(PageRequest request, GoodsBean goodsBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->goodsMapperImpl.findAll(request,goodsBean));
//        return goodsMapperImpl.findAll();
    }*/

    @Override
    public List<GoodsBean> findAll() {
        return goodsMapperImpl.findAll();
    }




    /**
     * 根据Id删除商品
     * 弱删除  修改删除状态
     *
     * @param id
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int deleteById(Integer id) {
        return goodsMapperImpl.deleteById(id);
    }

    /**
     * 查询销量前五
     *
     * @return
     */
    @Override
    public List<GoodsBean> findGoodsSoldTop5() {
        return goodsMapperImpl.findGoodsSoldTop5();
    }

    /**
     * 查询访问量前五
     *
     * @return
     */
    @Override
    public List<GoodsBean> findGoodsVisitedTop5() {
        return goodsMapperImpl.findGoodsVisitedTop5();
    }

    /**
     * 新增非实物商品
     *
     * @param goodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int saveGoods(GoodsBean goodsBean) {
        return goodsMapperImpl.saveGoodsBean(goodsBean);
    }

    /**
     * 新增实物商品
     *
     * @param goodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int saveEntity(GoodsBean goodsBean) {
        return goodsMapperImpl.saveGoodsBeanEntity(goodsBean);
    }

    /**
     * 修改非实物商品
     *
     * @param goodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int updateGoodsBean(GoodsBean goodsBean) {
        return goodsMapperImpl.updateGoodsBean(goodsBean);
    }

    /**
     * 修改实物商品
     *
     * @param goodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int updateEntity(GoodsBean goodsBean) {
        return goodsMapperImpl.updateEntity(goodsBean);
    }

    /**
     * 推荐设置
     * 0--推荐
     * 1--不推荐
     *
     * @param goodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int updateRecommend(GoodsBean goodsBean) {
        return goodsMapperImpl.updateRecommend(goodsBean);
    }

    /**
     * 下架
     * @param goodsBean
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    @Override
    public int updateStatus(GoodsBean goodsBean) {
        return goodsMapperImpl.updateStatus(goodsBean);
    }

    @Override
    public List<GoodsBean> findAllByParams(GoodsBean goodsBean) {
        return goodsMapperImpl.findAllByParams(goodsBean);
    }

    @Override
    public List<GoodsBean> findEntityParams(GoodsBean goodsBean) {
        return goodsMapperImpl.findEntityParams(goodsBean);
    }


    @Override
    public List<GoodsBean> findEntity() {
        return goodsMapperImpl.findEntity();
    }


}
